<%@ page language="java"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <title>材料列表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!-- 引用新样式 start -->
    <jsp:include page="../../jsp/public.jsp" flush="true"/>
    <!-- end -->
    <style type="text/css">
        .textBtn {
            position: absolute;
            right: 10px;
            bottom: 10px;
            top: 45px;
            right: 18px;
        }
    </style>
    <script>
        //提交表单
        function queryModelMeterList() {
            var data = $("#queryForm").serialize();
            window.location.href = "<%=path%>/bus/meter/meterList?" + data;
        }

        //跳转到新增页面
        function toAdd() {
            window.location.href = "<%=path%>/bus/meter/toAdd";
        }
        //跳转到修改页面
        function toEdit(id) {
        	$("#mapId").val(id);
        	var data = $("#queryForm").serialize();
            window.location.href = "<%=path%>/bus/meter/toEdit?"+data;
        }
        //触发上传按钮
        function uploadAnnex() {
            $("#logoFile3").click();
        }

        //上传文件
        function uploadExcel(obj) {
            var fileList = ".xlsx .XLSX .csv .CSV";
            var f = $(obj).val();
            var jq = f.lastIndexOf(".");
            var hz = f.substr(jq);
            // 批量上传图片
            if (fileList.indexOf(hz) >= 0) {
                if (!/.(xlsx|csv|png|XLSX|CSV)$/.test(f)) {
                    msgAlert("文件类型必须是xlsx,CSV中的一种");
                    return false;
                } else {
                    if (((obj.files[0].size).toFixed(2)) >= (10 * 1024 * 1024)) {
                        msgAlert("请上传小于10M的文件");
                        return false;
                    }
                }
            } else {
                msgAlert("上传的文件格式不正确");
                return false;
            }
            var id = layer.msg('上传中', {
                icon: 16
                , shade: 0.3,
                offset: 't', //坐标
                time: false
            });
            $.ajaxFileUpload({
                url: basePath + "/bus/meter/importMeter",// 需要链接到服务器地址
                secureuri: false,
                fileElementId: "logoFile3",// 文件选择框的id属性 ,//文件选择框的id属性
                dataType: 'json', // json
                contentType: false, // 不可缺
                processData: false, // 不可缺
                success: function (data) {
                    layer.close(id);//手动关闭
                    if (data.result == 'success') {
                        msgAlert("导入成功");
                        queryModelMeterList();
                    } else {
                        msgAlert("导入失败:"+data.result+"未找到");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    msgAlert("上传失败，请检查网络后重试");
                    layer.close(id);//手动关闭
                }
            });
        }
    </script>
<body>
<div class="col-lg-12">
    <div class="index-nav-right">
        <div class="index-nav-right-header"><span>当前位置 > 材料入库</span></div>
    </div>
    <div class="right-table">
        <div class="search-form" style=" border:0px solid #52bfff">
            <div class="search-form-input" style="width:60%;border:0px solid red">
                <form role="form" id="queryForm" method="post" action="<%=path%>/bus/meter/meterList">
						<input hidden = "true" type = "text" id = "mapId" name = "mapId">
						<input hidden = "true" type = "text" id = "mapPage" name ="mapPage" value="${map['page'] }">
                        <div  style="border: 0px solid red; display: inline">
                            <label>部品番号:</label>
                            <input type="text" name="modelCode" id="modelCode"
                                   value="${map['modelCode'] }"/>

                        </div>
                        <div style="border: 0px solid red; display: inline">
                            <label>厂家:</label>
                            <select name="factory" id="factory" style="width:200px;">
                                <c:if test="${not empty factory}">
                                    <option value=""></option>
                                    <c:forEach items="${factory }" var="factory" varStatus="m">
                                        <option value="${factory.orgCode }"
                                                <c:if test="${map['factory'] ==factory.orgCode }">selected</c:if>>${factory.orgName}</option>
                                    </c:forEach>
                                </c:if>
                            </select>
                        </div>
                        <div style="border: 0px solid red;display: inline">
                            <button type="submit" class="btn btn-primary search-form-btn-s" style="margin-left: 20px;color:black;"
                                    >搜索
                            </button>
                        </div>

                </form>
            </div>
            <div class="search-form-input" style="width:110px;border:0px solid red">
                <button class="btn btn-primary search-form-btn-s" style=" color:black;" onClick="toAdd()">新增</button>
            </div>
            <div class="search-form-input" style="width:45%;border:0px solid red">
                <div>
                    <input type="file" style="display:none" name="file" id="logoFile3"
                           onChange="uploadExcel(this)" class="btn navbar-default progress-btn"
                           accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"/>
                    <button class="btn btn-primary search-form-btn-s" id="test3" onClick="uploadAnnex()"
                            style=" color:black;height: 32px;">导入
                    </button>
                </div>
            </div>
        </div>

        <div class="index-table">
            <table class="table table-striped" action="<%=path%>/bus/meter/meterList">
                <thead>
                <tr class="table-thead">
                    <th>序号</th>
                    <th>厂家</th>
                    <th>部品番号</th>
                    <th>用途</th>
                    <th>材质</th>
                    <th>送长</th>
                    <th>宽幅</th>
                    <th>板厚</th>
                    <th>每枚可取数</th>
                    <th>入库数量</th>
                    <th>可取台数</th>
                    <th>操作</th>
                    <%--<th>已使用台数</th>--%>

                </tr>
                </thead>
                <tbody>
                <c:if test="${not empty list}">
                    <c:forEach items="${list }" var="meter" varStatus="r">
                        <tr>
                            <td>${r.index+1 }</td>
                            <td>${meter.factory }</td>
                            <td>${meter.modelCode }</td>
                            <td>${meter.useFor}</td>
                            <td>${meter.modelTexture }</td>
                            <td>${meter.grow }</td>
                            <td>${meter.wide }</td>
                            <td>${meter.tall }</td>
                            <td>${meter.perNum }</td>
                            <td>${meter.inventory }</td>
                            <td>${meter.planAmount }</td>
                            <td>
								<span  class="hand-like" onClick = "toEdit('${meter.id }')">修改</span>
							</td>
                        </tr>
                    </c:forEach>
                </c:if>
                <c:if test="${empty list}">
                    <tr>
                        <td colspan="11"><label class="control-label text-center">无记录</label></td>
                    </tr>
                </c:if>
                </tbody>
                <tr style="background: #f8f8f8">
                    <td colspan="12">
                        <jsp:include page="/WEB-INF/jsp/page2.jsp"></jsp:include>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript" src="<%=basePath%>js/progress/ajaxfileupload.js"></script>
</body>
</html>
